#!/usr/bin/python3
# exceptions.py by Bill Weinman [http://bw.org/]
# This is an exercise file from Python 3 Essential Training on lynda.com
# Copyright 2010 The BearHeart Gorup, LLC

def main():
    try:
        for line in readFile("lines.doc"):
            print(line.strip())
    except IOError as e:
        print("cannot open file", e)
    except ValueError as e:
        print("wrong file name:",e)        

def readFile(filename):
    if(filename.endswith(".txt")):    
        fh = open(filename)
        return fh.readlines()
    else:
        raise ValueError("file name must end with .txt")

if __name__ == "__main__": main()
